package com.laguille.games.monopoly.commons.event;

import org.apache.commons.lang.Validate;

import com.laguille.games.monopoly.commons.player.Player;

/**
 * Events representing the result of a dice throw.
 *
 */
public class DiceResultEvent extends Event {

	private final Player player;
	private final int firstThrow;
	private final int secondThrow;

	public final static int MIN_THROW_VALUE = 1;
	public final static int MAX_THROW_VALUE = 6;
	
	public DiceResultEvent(Player player, int firstThrow, int secondThrow) {
		Validate.notNull(player);
		Validate.isTrue(firstThrow >= MIN_THROW_VALUE &&  firstThrow <= MAX_THROW_VALUE);
		Validate.isTrue(secondThrow >= MIN_THROW_VALUE &&  secondThrow <= MAX_THROW_VALUE);
		this.player = player;
		this.firstThrow = firstThrow;
		this.secondThrow = secondThrow;
	}

	public Player getPlayer() {
		return player;
	}

	public int getFirstThrow() {
		return firstThrow;
	}

	public int getSecondThrow() {
		return secondThrow;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + firstThrow;
		result = prime * result + ((player == null) ? 0 : player.hashCode());
		result = prime * result + secondThrow;
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DiceResultEvent other = (DiceResultEvent) obj;
		if (firstThrow != other.firstThrow)
			return false;
		if (player == null) {
			if (other.player != null)
				return false;
		} else if (!player.equals(other.player))
			return false;
		if (secondThrow != other.secondThrow)
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "DiceResultEvent [player=" + player + ", firstThrow="
				+ firstThrow + ", secondThrow=" + secondThrow + "]";
	}
	
}
